//https://leetcode.cn/problems/single-number-ii/
class Solution {
public:
    int singleNumber(vector<int>& nums)
    {
        int ret = 0;
        for (int i = 0; i < 32; ++i)
        {
            int flag = 1 << i;
            int cnt = 0;
            for (int j = 0; j < nums.size(); ++j)
            {
                if ((nums[j] & flag) != 0)
                {
                    ++cnt;
                }
            }

            if (cnt % 3 != 0)
            {
                ret |= flag;
            }
        }

        return ret;
    }
};